package com.imooc.article.task;

import com.imooc.article.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;

/**
 * @Description :
 * @Author : YTY
 * @Date : 2020-12-04 16:15
 */

//@Configuration          // 1.标记配置类，使其能被 Spring Boot 容器扫描到
//@EnableScheduling       // 2.开启定时任务
public class TaskPublishArticles {

    @Autowired
    private ArticleService articleService;

    // 添加定时任务，注明定时任务表达式
    @Scheduled(cron = "0/3 * * * * ? ")
    private void publicArticles() {

        System.out.println("执行定时任务：" + LocalDateTime.now());

        // 定时发布文章
        articleService.updateAppointToPublish();
    }

}
